package com.mida.app.knw.controller;

import com.mida.app.knw.service.KnwNoumenonRelationService;
import com.mida.dms.knw.entity.vo.KnwNoumenonRelationVo;
import com.mida.dms.knw.entity.vo.MapperPage;
import com.mida.dms.knw.vo.KnwNoumenonRelationPageVo;
import com.mida.dms.knw.vo.PageResultVo;
import com.mida.dms.knw.vo.PullDownMenuOfNoumenonVO;
import com.mida.tool.common.result.ActionResult;
import com.mida.tool.common.result.ListResult;
import groovy.util.logging.Slf4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <h1>本体关系维护</h1>
 * <p>
 *
 * </p>
 *
 * @author jian.li on 2021/6/22 11:30
 */
@RestController
@RequestMapping("/knwNoumenonRelation")
@Api(tags = "本体关系维护")
@CrossOrigin
@Slf4j
public class KnwNoumenonRelationController {

    @Autowired
    KnwNoumenonRelationService relationService;

    /**
     * 新增关系
     */
    @ApiOperation(value = "新增关系", notes = "新增关系")
    @PostMapping(value = "/addRelation", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ActionResult add(@RequestBody KnwNoumenonRelationVo relation) {
        return relationService.add(relation);
    }

    @ApiOperation(value = "分页查询本体关系", notes = "分页查询本体关系")
    @PostMapping(value = "/findPage",produces = { "application/json;charset=UTF-8" })
    @ResponseBody
    public ListResult<PageResultVo<KnwNoumenonRelationVo>> findPage(@RequestBody KnwNoumenonRelationPageVo vo){
        return relationService.findPage(vo);
    }

    @ApiOperation(value = "启用本体关系", notes = "启用本体关系")
    @PutMapping(value = "/enable", produces = {"application/json;charset=UTF-8"})
    public ActionResult enable(@RequestParam Long soid) {
        return relationService.enable(soid);
    }

    /**
     * 源本体目标本体下拉
     */
    @ApiOperation(value = "源本体", notes = "根据源本体匹配目标")
    @PostMapping(value = "/findDataBySource", produces = {MediaType.APPLICATION_JSON_VALUE})
    @ResponseBody
    public ListResult<List<PullDownMenuOfNoumenonVO>> findSourceAndTarget(@RequestBody MapperPage knwNoumenon) {
        return relationService.findSourceAndTarget(knwNoumenon);
    }

    /**
     * 关系下拉(从概念域获取)
     */
    @ApiOperation(value = "关系下拉", notes = "关系下拉")
    @GetMapping(value = "/findRelation", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ListResult<Object> findRelation(@RequestParam String searchData) {
        return relationService.findRelation(searchData);
    }

    @ApiOperation(value = "编辑本体关系",notes = "编辑实例关系")
    @PostMapping(value = "/updateRelation",consumes = {"application/json;charset=UTF-8"},produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ActionResult updateSingle(@RequestBody KnwNoumenonRelationVo relation){
        return relationService.updateSingle(relation);
    }

    @ApiOperation(value = "删除本体关系",notes = "删除实例关系")
    @GetMapping(value = "/delete",produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ActionResult delete(@RequestParam("soid") Long soid) {
        return relationService.delete(soid);
    }
}

